package org.cwnuit.course.action;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.cwnuit.course.service.CourseboxService;
import org.cwnuit.course.util.ReflectionUtils;
/**
 * 排课信息表Controller
 * @author john
 */
@SuppressWarnings("serial")
public class CourseboxController extends HttpServlet {
	CourseboxService courseboxService = new CourseboxService();
	
	/**
	 * 进入管理员修改排课基本信息的界面
	 */
	public void courseboxRework(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		linkMsgRequest("基本信息的修改","box-info", "请认真填写排课基本信息！" , "web/coursebox/courseboxinput.jsp" , request, response);
	}
	/**
	 **跳转与提示信息 公共方法
	 **信息级别的描述-msgrank
	 *级别0-普通框 值空
	 *级别1-普通信息框 值box-info
	 *级别2-普通警告框 值box-warning
	 *级别3-普通错误框 值box-error
	 *级别4-错误信息列表框 值box-error-msg
	 *参数：标题 信息的样式 提示信息 跳转地址
	 */
	public void linkMsgRequest(String tittle, String msgrank, String msg, String linkStr, HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
		request.getSession().setAttribute("content_tittle",tittle);
		request.getSession().setAttribute("msgrank",msgrank);
		request.getSession().setAttribute("msg",msg);
		request.getRequestDispatcher(linkStr).forward(request,response);
	}
	//直接跳转
	public void linkMsg(String tittle, String msgrank, String msg, String linkStr, HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
		request.getSession().setAttribute("content_tittle",tittle);
		request.getSession().setAttribute("msgrank",msgrank);
		request.getSession().setAttribute("msg",msg);
		response.sendRedirect(linkStr);
	}
	
	/**
	 * 用户数据Controller过滤器
	 * cmd即为servlet中的方法名
	 * 公共方法，勿动！
	 */
	public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		String cmd = request.getParameter("cmd");
		Method method = ReflectionUtils.getDeclaredMethod(CourseboxController.class, cmd);
		try {
			if(method!=null){
				method.invoke(new CourseboxController(),request, response);
			}else{
				request.getRequestDispatcher("login.jsp").forward(request,response);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
